{{include file="public/header" /}}
<link rel="stylesheet" type="text/css" href="{{$public_host}}static/web/js/zTree_v3/css/zTreeStyle/zTreeStyle.css?v={{:MyC('home_static_cache_version')}}" />
<!-- right content start  -->
<div class="content-right">
    <div class="content">
        <!-- 温馨提示 -->
        <div class="am-alert am-alert-danger" data-am-alert>
            <button type="button" class="am-close">&times;</button>
            <p>1. 非专业技术人员请勿操作该页面数据、操作失误可能会导致权限菜单错乱。</p>
            <p>2. 如果出现权限菜单错乱，可以重新覆盖[ {{:config('database.prefix')}}user_goods_gategory ]数据表的数据恢复。</p>
            <b>3. 选中状态为不展示，反之展示</b>
        </div>

    {{if !empty($goods_cate)}}
        <form class="am-form form-validation view-save" action="{{:MyUrl('admin/user/editUserCategory')}}" method="POST" request-type="ajax-url" request-value="{{:MyUrl('admin/user/getUserCategory', $params)}}">
    <ul id="hidedata" style="display: none">
        {{foreach $goods_cate as $v}}
        <li>
            <input type="checkbox" name="cate" pcate value="{{$v['id']}}" text="{{$v['name']}}"  {{if $v['status'] eq 1}}checked="true" tagsel="checked" {{/if}}/>

            {{if !empty($v['items'])}}
            <ul style="margin-left: 8%">
                {{foreach $v['items'] as $m}}
                <li>

                    <input type="checkbox" name="cate" value="{{$m['id']}}" text="{{$m['name']}}" {{if $m['status'] eq 1}}checked="true" tagsel="checked" {{/if}}/>
<!--                    {{if !empty($m['items'])}}-->
<!--                    <ul>-->
<!--                        {{foreach $m['items'] as $s}}-->
<!--                        <li>-->
<!--                            {{$s['name']}}-->
<!--                        </li>-->
<!--                        {{/foreach}}-->
<!--                    </ul>-->
<!--                    {{/if}}-->
                </li>
                {{/foreach}}
            </ul>
            {{/if}}
        </li>
        {{/foreach}}
    </ul>
    <ul id="treeDemo" class="ztree"></ul>
            <div class="am-form-group am-form-group-refreshing am-margin-top-lg am-padding-left-0">
                <input type="hidden" name="id" {{if !empty($params)}} value="{{$params.id}}"{{/if}} />
                <button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm am-btn-block" data-am-loading="{loadingText:'处理中...'}">保存</button>
            </div>
        </form>
    {{/if}}
    </div>
</div>
<!-- right content end  -->

<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->
<script type='text/javascript' src="{{$public_host}}static/web/js/zTree_v3/js/jquery.ztree.core.js?v={{:MyC('home_static_cache_version')}}"></script>
<script type='text/javascript' src="{{$public_host}}static/web/js/zTree_v3/js/jquery.ztree.excheck.js?v={{:MyC('home_static_cache_version')}}"></script>

<SCRIPT type="text/javascript">

    var setting = {
        view: {
            showIcon: false
        },
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onCheck: onCheck
        }
    };
    var zNodes =[];
    var code, log, className = "dark";
    function onCheck(e, treeId, treeNode) {
        $("#hidedata li input[type='checkbox']").removeAttr("checked");
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
            nodes = zTree.getCheckedNodes(true);
        for (var i=0;i<nodes.length;  i++) {
            $("#hidedata").find("input[value=" + nodes[i].id + "]").attr("checked", nodes[i].checked);
            $("#hidedata").find("input[value="+nodes[i].id+"]").prop("checked",nodes[i].checked)
        }
        // $("#hidedata").find("input[value="+treeNode.id+"]").prop("checked",treeNode.checked)
    }


    $("#hidedata>li").each(function(){
        var pid = $(this).find('input').attr('value');
        var dftchk=false;
        if($(this).find('input').attr('tagsel')){
            dftchk=true;
        }else{
            dftchk=false;
        }
        zNodes.push({id:$(this).find('input').attr('value'), pId: 0, name: $(this).find('input').attr('text'), open: false,checked:dftchk});
        $(this).find("ul>li").each(function () {
            dftchk=false;
            if($(this).find('input').attr('tagsel')){
                dftchk=true;
            }else{
                dftchk=false;
            }
            zNodes.push({id:$(this).find('input').attr('value'), pId: pid, name: $(this).find('input').attr('text'), open: false,checked:dftchk});
        });
    });

    var code;


    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        var zTree = $.fn.zTree.getZTreeObj("treeDemo")
        var type = { "Y":'' + 's', "N":'p' + 's'};
        zTree.setting.check.chkboxType = type;
    });
    //-->
</SCRIPT>